<!DOCTYPE html>
<html lang="en">
<head>
    <title>添加</title>
    <link rel="stylesheet" href="${ctxPath!}/js/extend/formSelect/formSelects-v4.css"/>
    <%include("/WEB-INF/views/common/basejs.html"){}%>
    <script>
        //全局定义一次, 加载formSelects
        var formSelects;
        layui.config({
            base: '../js/extend/formSelect/' //此处路径请自行处理, 可以使用绝对路径
        }).extend({
            formSelects: 'formSelects-v4'
        }).use(['formSelects'],function(){
            formSelects=layui.formSelects;
        }).use(['form','layer','jquery'],function(){
            var form = layui.form
                ,layer = layui.layer,
                $=layui.jquery;
           //初始化上级资源菜单树形结构
           formSelects.data('pid','server',{
               url:basePath+'/dept/showDeptTree',
           });
            //提交form监听表单
            form.on('submit(save)',function(data){
                //console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                $.ajax({
                    url:basePath+'/dept/save',
                    type:'post',
                    data:data.field,
                    dataType:'json',
                    success:function(data){
                        if(data.code==0){
                            //更新父元素的表格
                            window.parent.query();
                            //添加成功之后关闭当前窗口
                            window.parent.closeAddPage();
                            window.parent.layer.msg(data.msg);
                        }
                    },
                    error:function(e){

                    }
                });

                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        });
    </script>
</head>
<body>
<form class="layui-form layui-form-pane" action="" style="width:96%;margin:10px auto">
    <!--开始-->
    <!--部门名称-->
    <div class="layui-form-item">
        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-block">
            <input name="deptName" type="text" lay-verify="required"  autocomplete="off" placeholder="请输入部门名称" class="layui-input">
        </div>
    </div>
    <!--上级部门-->
    <div class="layui-form-item">
        <label class="layui-form-label">上级部门</label>
        <div class="layui-input-block">
            <select name="pid" xm-select="pid" xm-select-radio xm-select-search>
                <option value="">请选择上级部门</option>
            </select>
        </div>
    </div>
    <!--排序-->
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input name="sort" type="number"  autocomplete="off" placeholder="请输入排序值" class="layui-input">
        </div>
    </div>
    <!--状态-->
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="开启" checked>
            <input type="radio" name="status" value="2" title="禁用" >
        </div>
    </div>
    <!--结束-->
    <div class="layui-form-item layui-hide">
        <button id="form-submit" class="layui-btn" lay-submit lay-filter="save">保存</button>
    </div>
</form>
</body>
</html>